﻿using System;
using com.eforceglobal.crux.configuration;
using com.eforceglobal.crux.configuration.FeatureManager;
using com.eforceglobal.crux.views;
using com.eforceglobal.crux.controllers;

public partial class Login : System.Web.UI.Page, ILogin
{
    LoginController _LoginController;

    protected void Page_PreInit(object sender, EventArgs e)
    {
        Page.Theme = CruxConfigurationManager.GetApplicationThemeName();
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        _LoginController = new LoginController(this);
        _LoginController.InitView(IsPostBack);
        IFeatureManager featureManager = FeatureManagerFactory.GetFeatureManager();
        if (featureManager.IsFeatureSupported("Application"))
        { pnlLogin.Visible = true; pnlApplicationDisabled.Visible = false; }
        else
        { pnlLogin.Visible = false; pnlApplicationDisabled.Visible = true; }
        lnkForgotPassword.Visible = featureManager.IsFeatureSupported("AllowForgotPassword");
    }

    protected void Username_Changed(object sender, EventArgs e)
    {
       
    }

    #region ILogin Members

    public string UserName
    {
        get
        {
            return txtUserName.Text.Trim();
        }
        set
        {
            txtUserName.Text = value;
        }
    }

    public string Password
    {
        get
        {
            return txtPassword.Text;
        }
        set
        {
            txtPassword.Text = value;
        }
    }

    public bool AccessDenied
    {
        get
        {
            return pnlAccessDenied.Visible;
        }
        set
        {
            pnlAccessDenied.Visible = value;
        }
    }

    #endregion
   
    protected void btnLogin_Click(object sender, EventArgs e)
    {
            _LoginController.Login();
    }


    //protected void btnChange_Click(object sender, EventArgs e)
    //{
    //    _LoginController.NavigateToResetPasswordAfterPasswordExpired();
    //}

    protected void BtnChng_Click(object sender, EventArgs e)
    {
        _LoginController.NavigateToResetPassword();
    }
    protected void btnContinue_Click(object sender, EventArgs e)
    {
        _LoginController.SetDataInSession();
    }


    //public bool IsPasswordExpired
    //{
    //    get
    //    {
    //        return pnlPasswordExpired.Visible;
    //    }
    //    set
    //    {
    //        pnlPasswordExpired.Visible = value;
    //        //pnlLogin.Visible = !value;
    //        pnlPasswordExpirationWarning.Visible = !value;
    //    }
    //}

    public int PasswordExpirationWarningDays
    {
        set
        {
            lblMessage.Text = lblMessage.Text + value + " day(s).";
        }
    }

    public bool IsPasswordExpirationWarningVisible
    {
        get
        {
            return pnlPasswordExpirationWarning.Visible;
        }
        set
        {
            pnlPasswordExpirationWarning.Visible = value;
            pnlLogin.Visible = !value;
           // pnlPasswordExpired.Visible = !value;
        }
    }
    protected void lnkForgotPassword_Click(object sender, EventArgs e)
    {
        _LoginController.NavigateToForgotPassword();
    }
}
